package com.yxmadoc.umlproject.service.impl;

import com.yxmadoc.umlproject.model.RepairPrice;
import com.yxmadoc.umlproject.repository.RepairPriceRepository;
import com.yxmadoc.umlproject.service.RepairPriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

@Service
public class RepairPriceServiceImpl implements RepairPriceService {

	@Autowired
	private RepairPriceRepository repository;

	@Override
	public RepairPrice save(RepairPrice repairPrice) {
		return repository.save(repairPrice);
	}

	@Override
	public void delete(Integer priceId) {
		if(!repository.exists(priceId)){
			throw new RuntimeException("无此报价ID！");
		}
		repository.delete(priceId);
	}

	@Override
	public Page<RepairPrice> findAllByRepairerId(String repairerId, Pageable pageable) {
		return repository.findAllByRepairerId(repairerId, pageable);
	}

	@Override
	public Page<RepairPrice> findAllByOrderId(Integer orderId, Pageable pageable) {
		return repository.findAllByOrderId(orderId, pageable);
	}
}
